<template>
  <div>
    <nav-bar :title="title" :isShow="false"></nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="name"
        name="name"
        label="姓名"
        placeholder="姓名"
        :rules="[{ required: true, message: '请填写姓名' }]"
      />
      <van-field
        v-model="telephone"
        name="telephone"
        label="手机号"
        placeholder="手机号"
      />
      <div style="margin: 16px;">
        <van-button  round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>

  </div>
</template>

<script>
import NavBar from '@/components/NavBar'
import { card_agency_add } from '@/api/service'

export default {
  components: {
    NavBar,
  },
  props: {
    user_id: String
  },
  data() {
    return {
      title: this.$route.meta.title || "",
      id: 0,
      openid: "",
      office_openid: "",
      name: "",
      telephone: "",
      is_agency: 0,
    };
  },
  computed:{
    agency(){
      if(this.is_agency === 1){
        return '已经授权'
      }else{
        return '未授权'
      }
    }
  },
  methods: {
    onSubmit(values) {
      const openid = localStorage.getItem("openid")
           
      values["office_openid"] = openid

      if(this.id===0){
        this.addCardAgencyInfo(values)   //增加
      }else{
        values["id"] = this.id
      }
    },

    addCardAgencyInfo(userInfo){
      card_agency_add(userInfo).then(res=>{
        console.log("addCardAgencyInfo:", res)
        if(res.data.id){
          this.$router.push(`/card_agency_confirm/${res.data.id}`)
        }
      }).catch(error => {
        if (error.response) {
          console.log(error.response.data);
        } else if (error.request) {
          console.log(error.request);
        } else {
          console.log('Error', error.message);
        }
        console.log(error.config);
      })
    },

    // updateAgencyContractInfo(contractInfo){
    //     agency_company_update(contractInfo).then(res=>{
    //       console.log('updateAgencyContractInfo', res)
    //       if(res.data.id){
    //         this.$router.push(`/agency_confirm/${res.data.id}`)
    //       }
    //     }).catch(error => {
    //       if (error.response) {
    //         console.log(error.response.data);
    //       } else if (error.request) {
    //         console.log(error.request);
    //       } else {
    //         console.log('Error', error.message);
    //       }
    //       console.log(error.config);
    //     })
    // },

    // getCardAgencyInfo(){
    //   const openid = localStorage.getItem('openid')
    //   if(openid){
    //     agency_company_info(this.company_id).then(res => {
    //       console.log("getAgencyCompanyInfo:",res)
    //       this.id = res.data.id
    //       this.name = res.data.name
    //       this.contact_person = res.data.contact_person
    //       this.contact_tel = res.data.contact_tel
    //       this.is_agency = res.data.is_agency
    //     }).catch(error => {
    //         if (error.response) {
    //           console.log("b:", error.response.status);
    //         } else if (error.request) {
    //           console.log(error.request);
    //         } else {
    //           console.log('Error', error.message);
    //         }
    //     })
    //   }
    // },
  },
  created() {

  },

};
</script>

<style  scoped>

</style>